package class_code.obj_2_extends;

class Animal {
    public int id = 1;
    protected String name = "纳西达";
    int age = 500;
    private String sex = "女";

    public Animal(int id, String name, int age, String sex) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    void eat() {
        System.out.println(this.name + "在吃饭");
    }

    void sleep() {
        System.out.println(this.name + "在睡觉");
    }

    void learn() {
        System.out.println(this.name + "在学习");
    }

}

class Dog extends Animal {

    public Dog(int id, String name, int age, String sex) {
        super(id, name, age, sex);
    }

    void helpMaster() {
        System.out.println(this.name + "在帮助主人！");
    }

}

class Cat extends Animal {

    public Cat(int id, String name, int age, String sex) {
        super(id, name, age, sex);
    }


}

public class ExtendsDemo1 {
    public static void main(String[] args) {
        Dog dog = new Dog(1, "大黄", 2, "男");

        System.out.println(dog.id);
        System.out.println(dog.name);
        System.out.println(dog.age);
//      private 修饰的字段不继承
//        System.out.println(dog.sex);

        dog.eat();
        dog.learn();


        Cat cat = new Cat(1, "猫猫", 2, "女");
        cat.eat();
    }
}